package com.estar.assistsurvy.adapter;

import java.util.List;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.grabList;
import com.estar.assistsurvy.utils.TimeUtils;
import com.estar.assistsurvy.widget.TimeTextView;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class grabAdapter extends BaseAdapter{

	private List<grabList> orders;
	private grabList order;
	private LayoutInflater inflater;
	public grabAdapter(List<grabList> orders, Context context) {
		this.orders = orders;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return orders.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return orders.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		viewHolder holder;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.listview_order, null);
			holder=new viewHolder();
			holder.castTime=(TextView) convertView.findViewById(R.id.castTime);
			holder.order_address=(TextView) convertView.findViewById(R.id.order_address);
			holder.order_distance=(TextView) convertView.findViewById(R.id.order_distance);
			holder.order_leftTime= (TimeTextView) convertView.findViewById(R.id.order_leftTime);
			holder.order_carNumber=(TextView) convertView.findViewById(R.id.order_carNumber);
			holder.orderCharge=(TextView) convertView.findViewById(R.id.orderCharge);
			holder.robOrder=(ImageView) convertView.findViewById(R.id.robOrder);
			holder.order_gpsIco=(ImageView) convertView.findViewById(R.id.order_gpsIco);
			holder.orderTime=(TextView) convertView.findViewById(R.id.orderTime);
			holder.order_carIco=(ImageView) convertView.findViewById(R.id.order_carIco);
			holder.orderDetail=(ImageView) convertView.findViewById(R.id.orderDetail);
			convertView.setTag(holder);
		}else{
			holder=(viewHolder) convertView.getTag();
		}

		order=orders.get(position);
		holder.castTime.setText(TimeUtils.EnglishToChinese(order.getUpdateTime()));
		holder.order_address.setText(order.getOccurPlace());
		holder.order_distance.setText(order.getDistance());
		holder.order_distance.setVisibility(View.GONE);
		holder.order_leftTime.setText("");
		holder.order_carNumber.setText(order.getTargetCar());
		holder.order_gpsIco.setImageResource(R.drawable.icon_address2);
//		holder.order_timeIco.setImageResource(R.drawable.icon_clock2);
		holder.orderTime.setText("");
		holder.order_carIco.setImageResource(R.drawable.icon_carnumber2);
		holder.orderDetail.setImageResource(R.drawable.btn_more);
		holder.robOrder.setImageResource(R.drawable.icon_scrambled);
		holder.orderCharge.setText(order.getPredictCharge());

		return convertView;
	}

	private class viewHolder{
		private TextView castTime,order_address,order_distance,
		order_carNumber,orderCharge,orderTime;
		private TimeTextView order_leftTime;
		private ImageView robOrder,order_gpsIco,order_carIco,orderDetail;

	}

}
